<template>
	<view class="uni-padding-wrap">
		<view class="header">
			<image src="../../static/logo.png" mode="widthFix" class="logo"></image>
		</view>
		<view class="myform">
			<view class="row">
				<label>账号</label>
				<input type="text" placeholder="请输入账号" @input="getAccount"/>
			</view>
			<view class="row">
				<label>密码</label>
				<input type="safe-password" placeholder="请输入密码" @input="getPwd"/>
			</view>
		</view>
		<view class="footer">
			<button type="primary" @click="login()">登录</button>
			<view class="nav">
				<navigator url="../forget/forget">忘记密码</navigator>
				<navigator url="../register/register" animation-type="slide-in-left" animation-duration="1000">用户注册</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Account: '',	// 当前页面
				account: '',    // 接收参数
				Pwd: '',  		// 当前页面
				pwd: ''			// 接收参数
			}
		},
		onLoad(e) {
			this.account = e.username;
			this.pwd = e.pwd
		},
		methods: {
			getAccount(e){
				this.Account = e.detail.value;
			},
			getPwd(e){
				this.Pwd = e.detail.value;
			},
			login() {
				if(this.Account == '') {
					uni.showToast({
						title: "请输入账号",
						icon: 'none'
					})
				} else if(this.Pwd == '') {
					uni.showToast({
						title: "请输入密码",
						icon: 'none'
					})
				} else {
					if((this.Account == this.account || this.Account == 'admin') && (this.Pwd == this.pwd || this.Pwd == 'admin')) {
						uni.showToast({
							title: '登录成功',
							icon: 'none'
						})
						uni.setStorageSync("token",this.Account + 'gzd_uniapp' + this.Pwd)
						uni.navigateTo({
							url: '../index/index',
							animationType: 'slide-in-left',
							animationDuration: 1000
						})
					} else {
						uni.showToast({
							title: '用户名或密码错误',
							icon: 'error'
						})
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.header {
		width: 100%;
		padding-top: 230upx;
		text-align: center;
		.logo {
			width: 150upx;
			border-radius: 20upx;
			margin-bottom:114upx;
		}
	}
	.myform {
		margin-bottom:114upx;
		.row {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			border: 1px solid #f9f9f9;
			padding: 5upx 15upx;
			border-radius: 20upx;
			line-height: 80upx;
			margin-bottom: 30upx;
		}
		label {
			width: 150upx;
		}
		input {
			flex: 1;
			text-align: left;
			padding-top: 15upx;
		}
	}
	.footer {
		margin: 0 auto;
		margin-top: 136upx;
		width: 612upx;
		button {
			height: 96upx;
			margin-bottom: 42upx;
		}
		.nav {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			line-height: 60upx;
			navigator {
				color: #999999;
			}
		}
	}
</style>
